import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/login/Login";
import animation from './routerBox/animation'
import demo from './routerBox/demo'
import promise from './routerBox/promise'
import anOralQuiz from './routerBox/anOralQuiz'
import vue3Lear from './routerBox/vue3Lear'
Vue.use(VueRouter);

const routes = [
  { path: "/", meta: { title: '登录页面' }, redirect: "/login" },
  { path: "/login", meta: { title: '登录页面' }, component: Login },
  { path: "/index", meta: { title: '首页' }, component: () => import("@/views/index/index"), 
    children: [
      { path: "/index/input", meta: { title: '输入框' }, component: () => import("@/views/components/input/index") },
      { path: "/index/tabbar", meta: { title: 'tabbar' }, component: () => import("@/views/components/tabbar/index") },
      { path: "/index/swiper", meta: { title: 'swiper' }, component: () => import("@/views/components/swiper/index") },
      { path: "/index/loginBox", meta: { title: '登录盒子' }, component: () => import("@/views/components/loginBox/index") },
      animation,//animation
      demo,//demo
      promise,//promise
      { path: "/index/surelyVue", meta: { title: '虚拟滚动' }, component: () => import("@/views/components/surelyVue/index") },
      { path: "/index/lodashTool", meta: { title: 'lodash' }, component: () => import("@/views/components/lodashTool/index") },
      { path: "/index/sortAlgorithm", meta: { title: 'sortAlgorithm' }, component: () => import("@/views/components/sortAlgorithm/index") },
      anOralQuiz,
      vue3Lear,
    ]
  },
];

const router = new VueRouter({
  mode: "history",
  routes,
});

//路由相同路由重复点击导致浏览器报错ß
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

//封装routes到菜单栏
export function createRoute() {
  let routesList = []
  for(let item of routes) {
    routesList.push(item)
  }
  routesList.splice(0, 2) //删除前路由前三个
  return routesList[0].children;
}

export default router;
